<template>
  <el-dialog
    title="机构选择"
    :close-on-click-modal="false"
    :visible.sync="visible"
    @close="clearDataList()"
    width="90vw"
    top="5vh"
    append-to-body
  >
    <el-container>
      <el-main style="height:70vh;overflow-x: hidden;">
        <el-row :gutter="20">
          <el-col :span="24" v-if="lastPage=='htcj'">
            <div style="margin-bottom: 10px">
              数据范围:&nbsp;
              <el-radio-group v-model="radioTwo">
                <el-radio v-for="(item,index) in radioTwoList" :key="index" :label="item.value">
                  {{
                  item.name
                  }}
                </el-radio>
              </el-radio-group>
            </div>
            <div class="flex" style="margin-bottom: 10px">
              <span>快捷选择：</span>
              <div class="flex" style="align-items: center;">
                <div @mouseover="handleMouseOver" @mouseleave="handleMouseleave">
                  <el-checkbox
                    :indeterminate="isIndeterminate"
                    :disabled="!qjDeptId"
                    v-model="quickCheckAll"
                    @change="handleQuickCheckAllChange"
                  >全选</el-checkbox>
                  <span v-if="visibleTip&&!qjDeptId" style="margin-left: 20px;color:#f00">需选择单位</span>
                </div>
                <div style="margin-left: 20px;" v-if="qjDeptId">
                  <el-checkbox-group
                    v-model="quickCheckedPost"
                    @change="handleQuickCheckedPostsChange"
                  >
                    <el-checkbox
                      :indeterminate="post.isIndeterminate"
                      v-for="post in postList"
                      :label="post.postCheckName"
                      :key="post.userId"
                    >{{post.postCheckName}}</el-checkbox>
                  </el-checkbox-group>
                </div>
              </div>
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :md="5">
            <div class="boxsty">
              <el-tree
                :data="treeData"
                :props="defaultProps"
                :filter-node-method="filterNode"
                class="filter-tree"
                node-key="id"
                highlight-current
                :default-expanded-keys="[1]"
                accordion
                @node-click="getNodeData"
              />
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :md="8">
            <div class="boxsty" v-if="showPrise">
              <div class="flex titbottom">
                <el-input v-model="listQuery.name" placeholder="请输入搜索用户" style="margin-right:10px"></el-input>

                <el-button @click="btnSearch" type="primary" icon="el-icon-search" plain>搜索</el-button>
              </div>
              <div class="avue-crud">
                <el-table
                  @row-click="handleClick"
                  :data="tableDataDept"
                  v-loading="tableloading"
                  style="width: 100%"
                >
                  <el-table-column prop="username" label="用户" width="120"></el-table-column>
                  <el-table-column prop="ryName" label="姓名" min-width="150"></el-table-column>
                  <el-table-column v-if="lastPage=='htcj'" prop="ryZjmc" label="职级" min-width="100"></el-table-column>
                </el-table>
              </div>
              <div style="margin-top:20px;">
                <el-pagination
                  @size-change="sizeChangeHandle"
                  @current-change="currentChangeHandle"
                  :current-page="page.currentPage"
                  :page-sizes="[10, 20, 50, 100]"
                  :page-size="page.pageSize"
                  :total="page.total"
                  background
                  layout="total, sizes, prev, pager, next"
                >
                  <!-- , jumper -->
                </el-pagination>
              </div>
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :md="11">
            <div class="boxsty" v-if="showPrisehidden">
              <!--             原来是叫【已选择机构】在合同创建受约人的地方不对，所以改成【已选择人员】-->
              <div class="tabletext titbottom">
                已选择人员
                <el-button class="pull-right" plain type="primary" @click="tableDataUser=[]">清空</el-button>
              </div>
              <div class="avue-crud">
                <el-table :data="tableDataUser" ref="ry-table" stripe>
                  <el-table-column prop="sx" label="顺序" width="90"></el-table-column>
                  <el-table-column prop="userName" label="姓名" width="100"></el-table-column>
                  <el-table-column prop="deptName" label="部门" min-width="220"></el-table-column>
                  <el-table-column v-if="lastPage=='htcj'" prop="ryZjmc" label="职级" min-width="100"></el-table-column>
                  <el-table-column fixed="right" label="操作" width="100">
                    <template slot-scope="scope">
                      <el-button @click="delUserList(scope.$index)" type="danger" plain>删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>

            <div class="boxsty" v-if="showRentPrise">
              <!--             原来是叫【已选择人员】在合同创建受约人的地方不对，所以改成【已选择机构】-->
              <div class="tabletext titbottom">已选择机构</div>
              <div class="avue-crud">
                <el-table :data="tableDataUser" ref="ry-table" stripe>
                  <el-table-column prop="jigouName" label="机构名称" width="300"></el-table-column>
                  <el-table-column label="操作" width="100">
                    <template slot-scope="scope">
                      <el-button @click="delUserList(scope.$index)" type="danger" plain>删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </el-col>
        </el-row>
      </el-main>
    </el-container>
    <span slot="footer" class="dialog-footer">
      <!-- <el-button type="primary" @click="exportExcel" style="float: left">导出已选人员</el-button> -->
      <el-button type="primary" plain @click="btnCancel">取消</el-button>
      <el-button type="primary" v-if="canSubmit" @click="btnSave">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import store from "@/store";
    import { radioTwoList } from "@/api/hetongrenwu/hetonghtxxdjb";
    import { alltree } from "@/api/hetongrenwu/hetongyeji/hetongnd";
    import { fetchList, allDeptsUsers } from "@/api/admin/user";
    import { fayuetree } from "@/api/hetongrenwu/hetongyeji/hetongnd";
    import { shouyuetree } from "@/api/hetongrenwu/hetongyeji/hetongnd";
    import { getMyDept } from "@/api/dailyExamine/eventExamine/event";
    import { showJgTree } from "@/api/dailyExamine/targetExamine/createAssessment";

    import { submitBmry } from "@/api/statisticsanalysis/pfhzbmhzApi";

    import {
        selHzBmList,
        savelist,
        removeByHzId
    } from "@/api/ceping/cepinghzgldxpzb";

    import { validatenull } from "@/util/validate";

    import { fetchTree } from "@/api/admin/dept.js";
    export default {
        props: {
            zid: String
        },
        data() {

            return {
                token: "",
                type: "",
                qjDeptId: "", //全局部门id
                qjGzId: "", //全局规则id
                tableloading: false, //table遮挡
                showPrise: true,
                showPrisehidden: true,
                showRentPrise: false,
                visible: false,
                canSubmit: false,
                tableDataDeptUse: [],
                tableDataDeptAll: [],
                tableDataDept: [],
                tableDataUser: [],
                dataForm: {},
                listQuery: {
                    name: ""
                },
                treeData: [],
                jgtreeData: [],
                defaultProps: {
                    children: "children",
                    label: "name"
                },
                page: {
                    total: 0, // 总页数
                    currentPage: 1, // 当前页数
                    pageSize: 20, // 每页显示多少条,
                    isAsc: false // 是否倒序
                },
                searchForm: {},
                zdySearchForm: {},
                nodeKey: [],
                radioTwo: "1",
                isOnly: false,
                radioTwoList: radioTwoList,
                isIndeterminate: false,
                visibleTip: false,
                postList: [],
                quickCheckedPost: [],
                quickCheckAll: false,
                lastPage: "",
                isFather: ""
            };
        },
        watch: {
            radioTwo(newVal) {
                this.isOnly = newVal == "-1" ? true : false;
                if (!this.qjDeptId) {
                    // this.$notify.closeAll();
                    // this.$notify.error('请选择机构！');
                    return false;
                }
                var params = {
                    deptId: this.qjDeptId
                };
                if (newVal == "1") {
                    this.getPersons(this.page, params);
                } else {
                    //全部 isOnly=true， 所属机构 isOnly=false
                    this.allDeptsUsers(this.page, params);
                }
            },
            //检测已选择人员的表格变化，来回填快捷选择的复选框
            tableDataUser: {
                handler(newVal, oldVal) {
                    if (this.lastPage == "htcj") {
                        this.quickCheckAll = false;
                        this.quickCheckedPost = [];
                        this.isIndeterminate = false;
                        this.postList = this.postList.map(item => {
                            item.isIndeterminate = false;
                            return item;
                        });
                        if (newVal.length == 0) {
                            return false;
                        }
                        //找出当前机构下面的已选择的人员信息
                        //var currentDeptData=newVal.filter(item=>item.deptId==this.qjDeptId);
                        var currentDeptData = newVal.filter(item =>
                            item.qjDeptIdArr.includes(this.qjDeptId)
                        );
                        if (currentDeptData.length > 0) {
                            //把已选择的人员信息数据重组，为了知道每个职位有多少人
                            var selectedUserDataPostCheckNameArr = [];
                            currentDeptData.forEach(item => {
                                var index = selectedUserDataPostCheckNameArr.findIndex(
                                    i => i.postCheckName == item.postCheckName
                                );
                                if (index == -1) {
                                    var filterData = currentDeptData.filter(
                                        obj => obj.postCheckName == item.postCheckName
                                    );
                                    selectedUserDataPostCheckNameArr.push({
                                        postCheckName: item.postCheckName,
                                        postCheckNameNum: filterData.length
                                    });
                                }
                            });
                            this.quickCheckedPost = [];
                            selectedUserDataPostCheckNameArr.forEach(item => {
                                var index = this.postList.findIndex(
                                    postItem => postItem.postCheckName == item.postCheckName
                                );
                                if (index != -1) {
                                    if (
                                        this.postList[index].postCheckNameNum ==
                                        item.postCheckNameNum ||
                                        this.postList[index].postCheckNameNum < item.postCheckNameNum
                                    ) {
                                        var quickDataIndex = this.quickCheckedPost.findIndex(
                                            quickItem => quickItem == item.postCheckName
                                        );
                                        if (quickDataIndex == -1) {
                                            this.quickCheckedPost.push(item.postCheckName);
                                        }
                                        this.postList[index].isIndeterminate = false;
                                    } else {
                                        this.postList[index].isIndeterminate = true;
                                        this.isIndeterminate = true;
                                    }
                                } else {
                                    this.postList[index].isIndeterminate = false;
                                }
                            });
                            this.quickCheckAll =
                                this.quickCheckedPost.length === this.postList.length;
                            this.isIndeterminate =
                                this.quickCheckedPost.length > 0 &&
                                this.quickCheckedPost.length < this.postList.length;
                        }
                    }
                },
                deep: true,
                immediate: true
            }
        },
        created() {
            // this.getList();

        },
        methods: {
            init(id, type, jsonData, isFather,lastPage) {
                this.token = store.getters.access_token;
                this.type = type;
                this.qjGzId = id;
                this.visible = true;
                this.canSubmit = true;
                this.isFather = isFather;
                this.lastPage = lastPage;
                //this.loadTableDataUser(id);
                this.getList();
                this.clearDataList();
                this.reloadTableDataUser(type, jsonData);
            },
            reloadTableDataUser(type, jsonData) {
                var jsonObj = JSON.parse(jsonData) || [];
            },
            //查询被测评对象
            loadTableDataUser(id) {
                selHzBmList(id)
                    .then(data => {
                        var obj = data.data.data;
                        if (obj) {
                            for (var i = 0; i < obj.length; i++) {
                                this.tableDataUser.push({
                                    id: obj[i].id,
                                    hzId: obj[i].hzId,
                                    userId: obj[i].userId,
                                    userName: obj[i].userName,
                                    deptId: obj[i].deptId,
                                    deptName: obj[i].deptName,
                                    userZw: obj[i].userZw,
                                    userLx: obj[i].userLx,
                                    userDeptId: obj[i].userDeptId,
                                    userDeptName: obj[i].userDeptName,
                                    bhzPx: obj[i].bhzPx
                                });
                            }
                        }
                    })
                    .catch(() => {
                        this.$notify.closeAll();
                        this.$notify.error("数据错误");
                    });
            },
            getList() {
                if (this.type == "fy") {
                    fayuetree(this.listQuery).then(response => {
                        this.treeData = response.data.data;
                        //this.treeData=this.jiequ(this.treeData)
                        this.treeData = response.data.data;
                        this.showPrise = true; // 机构人员显示
                        this.showPrisehidden = true; //右侧添加人显示
                        this.showRentPrise = false; // 机构隐藏
                    });
                } else if (this.type == "sy") {
                    shouyuetree(this.listQuery).then(response => {
                        this.treeData = response.data.data;
                        this.showPrise = true; // 机构人员显示
                        this.showPrisehidden = true; //右侧添加人显示
                        this.showRentPrise = false; // 机构隐藏
                    });
                } else if (this.type == "jg") {
                    shouyuetree(this.listQuery).then(response => {
                        this.treeData = response.data.data;
                        this.showPrise = false; // 机构人员隐藏
                        this.showPrisehidden = false; // 右侧添加人隐藏
                        this.showRentPrise = true; // 右侧添加机构显示
                    });
                } else if (this.type == "bkhr") {
                    shouyuetree(this.listQuery).then(response => {
                        this.treeData = response.data.data;
                        this.showPrise = true; // 机构人员显示
                        this.showPrisehidden = true; //右侧添加人显示
                        this.showRentPrise = false; // 机构隐藏
                    });
                } else if (this.type == "allTree")
                    alltree(this.listQuery).then(response => {
                        this.treeData = response.data.data;
                        this.showPrise = true; // 机构人员显示
                        this.showPrisehidden = true; //右侧添加人显示
                        this.showRentPrise = false; // 机构隐藏
                    });
                if (this.type == "cyr" || this.type == "shr" || this.type == "dfr") {
                    //參與人
                    fetchTree().then(response => {
                        this.treeData = response.data.data;
                    });
                }
                if (this.type == "sjkh") {
                    showJgTree().then(response => {
                        /*getMyDept().then((response) => {*/
                        this.treeData = response.data.data;

                    });
                }
                if (this.type == "zxshr") {
                    //专项审核
                    fayuetree(this.listQuery).then(response => {
                        this.treeData = response.data.data;
                    });
                }
            },
            jiequ(data) {
                const result = data.map(item => {
                    const children = item.children.map(every => {
                        return {
                            id: every.id,
                            parentId: every.parentId,
                            name: every.name,
                            deptName: every.deptName,
                            deptCode: every.deptCode,
                            isLock: every.isLock
                        };
                    });
                    return {
                        ...item,
                        children: children
                    };
                });
                return result;
            },
            filterNode(value, data) {
                if (!value) return true;
                return data.label.indexOf(value) !== -1;
            },
            //获取机构下面所有的人员
            allDeptsUsers(page, params) {
                this.tableloading = true;
                params["deptId"] = params.deptId ? params.deptId : this.qjDeptId;
                params["isOnly"] = this.isOnly;
                allDeptsUsers(
                    Object.assign(page, params, this.searchForm, this.zdySearchForm)
                )
                    .then(response => {
                        var arr = response.data.data;
                        this.tableDataDeptAll = arr.map(item => {
                            if (item.ryZjmc) {
                                item.postCheckName = item.ryZjmc;
                            } else {
                                item.postCheckName = "[无职级]";
                            }
                            return item;
                        });
                        this.page.total = arr.length;
                        this.tableloading = false;
                        if (this.lastPage == "htcj") {
                            this.postList = [];
                            this.tableDataDeptAll.forEach(item => {
                                var obj = this.postList.find(
                                    post => post.postCheckName == item.postCheckName
                                );
                                if (!obj) {
                                    var filterData = this.tableDataDeptAll.filter(
                                        obj => obj.postCheckName == item.postCheckName
                                    );
                                    this.postList.push(
                                        Object.assign(item, { postCheckNameNum: filterData.length })
                                    );
                                }
                            });
                            this.getAllUsersWithPage(page);
                            this.handleFillInData();
                        }
                        //给机关下的人力资源部排序
                        if (this.qjDeptId == 5) {
                            function sortData(obj1, obj2) {
                                return obj1.userId - obj2.userId;
                            }
                            this.getAllUsersWithPage(page);
                            this.tableDataDept = this.tableDataDept.sort(sortData);
                        }
                    })
                    .catch(err => {
                        this.tableloading = false;
                    });
            },
            getAllUsersWithPage(page) {
                const start = (page.currentPage - 1) * page.pageSize;
                const end = (page.currentPage - 1) * page.pageSize + page.pageSize;
                this.tableDataDept = this.tableDataDeptAll.slice(start, end);
                this.$forceUpdate();
            },
            getPersons(page, params) {
                this.tableloading = true;
                fetchList(
                    Object.assign(
                        { current: page.currentPage, size: page.pageSize },
                        params,
                        this.searchForm,
                        this.zdySearchForm
                    )
                )
                    .then(response => {
                        // this.list = response.data.data.records
                        var arr = response.data.data.records;
                        this.tableDataDept = arr.map(item => {
                            if (item.ryZjmc) {
                                item.postCheckName = item.ryZjmc;
                            } else {
                                item.postCheckName = "[无职级]";
                            }
                            return item;
                        });
                        this.page.total = response.data.data.total;
                        this.tableloading = false;
                        if (this.lastPage == "htcj") {
                            this.postList = [];
                            this.tableDataDept.forEach(item => {
                                var obj = this.postList.find(
                                    post => post.postCheckName == item.postCheckName
                                );
                                if (!obj) {
                                    var filterData = this.tableDataDept.filter(
                                        obj => obj.postCheckName == item.postCheckName
                                    );
                                    this.postList.push(
                                        Object.assign(item, { postCheckNameNum: filterData.length })
                                    );
                                }
                            });
                            this.handleFillInData();
                        }
                        //给机关下的人力资源部排序
                        if (this.qjDeptId == 5) {
                            function sortData(obj1, obj2) {
                                return obj1.userId - obj2.userId;
                            }
                            this.tableDataDept = this.tableDataDept.sort(sortData);
                        }
                    })
                    .catch(err => {
                        this.tableloading = false;
                    });
            },
            //复选框的回填
            handleFillInData() {
                this.quickCheckAll = false;
                this.quickCheckAll = false;
                this.quickCheckedPost = [];
                this.isIndeterminate = false;
                // var currentOrgArr=this.tableDataUser.filter(item=>item.deptId==this.qjDeptId);
                var currentOrgArr = this.tableDataUser.filter(item =>
                    item.qjDeptIdArr.includes(this.qjDeptId)
                );
                currentOrgArr.forEach(item => {
                    var postIndex = this.postList.findIndex(
                        postItem => postItem.postCheckName == item.postCheckName
                    );
                    if (postIndex != -1) {
                        if (
                            this.postList[postIndex].postCheckNameNum == currentOrgArr.length ||
                            this.postList[postIndex].postCheckNameNum < currentOrgArr.length
                        ) {
                            var obj = this.quickCheckedPost.find(
                                checkPost => checkPost == item.postCheckName
                            );
                            if (!obj) {
                                this.quickCheckedPost.push(item.postCheckName);
                            }
                            this.postList[postIndex].isIndeterminate = false;
                        } else {
                            this.postList[postIndex].isIndeterminate = true;
                        }
                    }
                });
                this.quickCheckAll =
                    this.quickCheckedPost.length === this.postList.length;
                this.isIndeterminate =
                    this.quickCheckedPost.length > 0 &&
                    this.quickCheckedPost.length < this.postList.length;
                // this.handleQuickCheckedPostsChange(this.quickCheckedPost)
            },
            getNodeData(data) {
                if (this.type != "jg") {
                    this.page.currentPage = 1;
                    this.qjDeptId = data.id;
                    var paramsData = { deptId: data.id };
                    if (this.radioTwo == "1") {
                        this.getPersons(this.page, paramsData);
                    } else {
                        this.allDeptsUsers(this.page, paramsData);
                    }
                } else {
                    this.handleClick(data);
                }
            },
            //选人添加到右边的框
            handleClick(vm) {
                if (this.type != "jg") {
                    for (var i = 0; i < this.tableDataUser.length; i++) {
                        if (this.tableDataUser[i].userId == vm.userId) {
                            return;
                        }
                    }
                }
                if (this.type == "jg") {
                    for (var i = 0; i < this.tableDataUser.length; i++) {
                        if (this.tableDataUser[i].deptId == vm.id) {
                            return;
                        }
                    }
                }
                let objUser = {};
                objUser["hzId"] = this.qjGzId;
                objUser["userId"] = vm.userId;
                if (this.type == "fy") {
                    objUser["fayueName"] = vm.ryName;
                    objUser["fayueZhiwu"] = validatenull(vm.ryZw) ? "-" : vm.ryZw;
                } else if (this.type == "sy") {
                    objUser["shouyueName"] = vm.ryName;
                    objUser["ryZjmc"] = vm.ryZjmc;
                    objUser["shouyueZhiwu"] = validatenull(vm.ryZw) ? "-" : vm.ryZw;
                } else if (this.type == "bkhr") {
                    objUser["beikaoheName"] = vm.ryName;
                    objUser["beikaoheZhiwu"] = validatenull(vm.ryZw) ? "-" : vm.ryZw;
                }
                if (this.type == "jg") {
                    objUser["jigouName"] = vm.name;
                    objUser["userName"] = vm.name;
                    objUser["deptId"] = vm.id;
                } else {
                    objUser["userName"] = vm.ryName;
                    objUser["deptId"] = vm.deptId;
                }
                if (this.type == "cyr") {
                    objUser["cyrName"] = vm.ryName;
                    objUser["cyrydepartname"] = validatenull(vm.ryZw) ? "-" : vm.ryZw;
                }
                if (this.type == "zxshr") {
                    objUser["shrName"] = vm.ryName;
                    objUser["shrZhiwu"] = validatenull(vm.ryZw) ? "-" : vm.ryZw;
                }
                objUser["userZj"] = vm.ryZjmc;
                objUser["deptCode"] = vm.deptCode;
                objUser["userName"] = vm.ryName;
                objUser["deptName"] = vm.deptName;
                objUser["postCheckName"] = vm.postCheckName; //辅助快捷选择的
                objUser["userZw"] = validatenull(vm.ryZw) ? "-" : vm.ryZw;
                objUser["type"] = this.type;
                objUser["userLx"] = "个人";
                objUser["userCode"] = vm.username;
                // objUser["sx"] = 0;
                //点过的机构id数据用于快捷选择的复选框回填辅助开发
                objUser["qjDeptIdArr"] = objUser["qjDeptIdArr"] || [];
                const index = objUser["qjDeptIdArr"].findIndex(
                    item => item == this.qjDeptId
                );
                if (index == -1) {
                    objUser["qjDeptIdArr"].push(this.qjDeptId);
                }
                const index2 = objUser["qjDeptIdArr"].findIndex(
                    item => item == vm.deptId
                );
                if (index2 == -1) {
                    objUser["qjDeptIdArr"].push(vm.deptId);
                }
                /*   if (
                       this.multiMode == 1 &&
                       this.titleName == "编辑" &&
                       this.type == "sy"
                   ) {
                       this.tableDataUser = [];
                   }*/
                this.tableDataUser.unshift(objUser);
                if (this.type == "shr") {
                    this.tableDataUser = [];
                    this.tableDataUser.unshift(objUser);
                }
                var lengths = this.tableDataUser.length + 1;
                this.tableDataUser.forEach(ele => {
                    lengths--;
                    ele.sx = lengths;
                });
            },
            //删除人员list
            delUserList(index) {
                this.tableDataUser.splice(index, 1);
                var lengths = this.tableDataUser.length + 1;
                this.tableDataUser.forEach(ele => {
                    lengths--;
                    ele.sx = lengths;
                });
            },
            //清空记录
            clearDataList() {
                this.qjDeptId = "";
                this.tableDataDept = [];
                this.tableDataUser = [];
                this.tableDataUserAll = [];
                this.tableDataDeptUse = [];
                this.radioTwo = "1";
            },
            //保存人员
            btnSave() {

                let userIds =[];
                this.tableDataUser.map(it =>{
                    userIds.push(it.userId);
                })

                this.canSubmit = false;
                this.visible = false;

                 var params = {
                   tableDataUser: this.tableDataUser.reverse(),
                   type: this.type,
                   isFather: this.isFather
                 };
                 this.$emit("submitfy", params);
            },
            // tree搜索事件,搜索人
            btnSearch() {
                let param = {
                    deptId: this.qjDeptId
                };

                if (this.listQuery.name.trim() !== "") {
                    param["username"] = this.listQuery.name.trim();
                    param["ryName"] = this.listQuery.name.trim();
                }
                this.getPageUsers(param);
            },
            // 分页
            // 每页数
            sizeChangeHandle(val) {
                this.page.pageSize = val;
                this.page.currentPage = 1;
                if (this.radioTwo == 1) {
                    this.getPageUsers();
                } else {
                    this.getAllUsersWithPage(this.page);
                }
            },
            // 当前页
            currentChangeHandle(val) {
                this.page.currentPage = val;
                if (this.radioTwo == 1) {
                    this.getPageUsers();
                } else {
                    this.getAllUsersWithPage(this.page);
                }
            },
            //分页刷新
            getPageUsers(vm) {
                if (vm) {
                    if (this.radioTwo == 1) {
                        this.getPersons(this.page, vm);
                    } else {
                        this.allDeptsUsers(this.page, vm);
                    }
                } else {
                    if (this.radioTwo == 1) {
                        this.getPersons(this.page, {
                            deptId: this.qjDeptId
                        });
                    } else {
                        this.allDeptsUsers(this.page, {
                            deptId: this.qjDeptId
                        });
                    }
                }
            },
            //取消按钮
            btnCancel() {
                this.visible = false;
                this.clearDataList();
            },
            /**
             * excel 导出
             */
            exportExcel() {
                try {
                    // 导出
                    require.ensure([], () => {
                        const { export_json_to_excel } = require("@/util/Export2Excel");
                        const tHeader = "用户,姓名,部门".split(",");
                        const filterVal = "xsUserName,ryName,deptName".split(",");
                        const list = this.tableDataUser.map(column =>
                            filterVal.map(header => {
                                return column[header];
                            })
                        );
                        export_json_to_excel(tHeader, list, "已选人员名单");
                    });
                } catch (e) {
                    if (typeof console !== "undefined") console.error(e);
                }
            },
            //判空
            validatenull(val) {
                return validatenull(val);
            },
            //*快捷选择*/
            handleMouseOver() {
                this.visibleTip = true;
            },
            handleMouseleave() {
                this.visibleTip = false;
            },
            handleQuickCheckAllChange(val) {
                if (this.radioTwo == "1") {
                    this.tableDataDeptUse = JSON.parse(JSON.stringify(this.tableDataDept));
                } else {
                    this.tableDataDeptUse = JSON.parse(
                        JSON.stringify(this.tableDataDeptAll)
                    );
                }
                var quickCheckedPostList = this.postList.map(item => item.postCheckName);
                this.quickCheckedPost = val ? quickCheckedPostList : [];
                this.isIndeterminate = false;
                if (this.quickCheckAll) {
                    this.tableDataDeptUse.forEach(item => {
                        this.handleClick(item);
                    });
                }
            },
            handleQuickCheckedPostsChange(value) {
                if (this.radioTwo == "1") {
                    this.tableDataDeptUse = JSON.parse(JSON.stringify(this.tableDataDept));
                } else {
                    this.tableDataDeptUse = JSON.parse(
                        JSON.stringify(this.tableDataDeptAll)
                    );
                }
                //把已选择的人员的地方非当前机构的数据挑出来
                //this.tableDataUser=this.tableDataUser.filter(item=>item.deptId!=this.qjDeptId);
                this.tableDataUser = this.tableDataUser.filter(
                    item => !item.qjDeptIdArr.includes(this.qjDeptId)
                );
                //当前机构的数据以选择的为准
                let checkedCount = value.length;
                this.quickCheckAll = checkedCount === this.postList.length;
                this.isIndeterminate =
                    checkedCount > 0 && checkedCount < this.postList.length;
                var needCheckData = [];
                this.quickCheckedPost.forEach(checkPost => {
                    needCheckData = [
                        ...needCheckData,
                        ...this.tableDataDeptUse.filter(
                            item => item.postCheckName == checkPost
                        )
                    ];
                });
                needCheckData.forEach(item => {
                    this.handleClick(item);
                });
            }
        }
    };
</script>

<style scoped>
  .hide-box {
    display: none;
  }
</style>
